<?php

namespace slinks\common\io;

/**
 * Reads all annotations from a given file system path or array of paths. 
 * @author navid
 *
 */
use slinks\common\Finder\Finder;

class AnnotationReader {
    /* @var $classReader ClassReader */

    private $classReader = null;

    /* @var $annotationReader AnnotationClassVisitor */
    private $annotationReader = null;

    public function __construct(IAnnotationVisitor $annotationVisitor) {
        $this->annotationReader = new AnnotationClassVisitor($annotationVisitor);
        $this->classReader = new ClassReader($this->annotationReader);
    }

    /**
     * Reads all Annotations from the filesystem begining at the given directory.
     * @param Finder $finder the Finder configured to read the annotations from the underlying classes you want visited.
     * @param bool $skipErrors true to skip any errors encountered while reading annotations from the classes.  Default is false.
     */
    public function read(Finder $finder, $skipErrors = false) {
        $this->annotationReader->setSkipErrors($skipErrors);
        $this->classReader->read($finder);
    }

}

